import { Button, Form, Input } from 'antd';
import React from 'react';
import "../css/login.css"
import userinfo from "../model/userinfo/Userinfo"
import { useHistory } from 'react-router-dom';
const App: React.FC = () => {
    let history = useHistory()
    const onFinish = async ({ username, userpwd }: any) => {
        let { data } = await userinfo.login({ username, userpwd })
        if (data.code == 1) {
            history.push("/main")
        }
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
    };

    return (
        <div className='loginbox'>
            <Form
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 6 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
            >
                <Form.Item
                    label="用户名"
                    name="username"
                    rules={[{ required: true, message: '用户名不能为空!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="userpwd"
                    rules={[{ required: true, message: '请输入密码!' }]}
                >
                    <Input.Password />
                </Form.Item>


                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit">
                        登录
                    </Button>
                </Form.Item>
            </Form>
        </div>
    );
};

export default App;